package com.ds.lens.data.common.error;

/**
 * Description:
 *
 * @author WeiShaoying
 * @date 2019-07-15
 */
public class ErrorCodeException extends RuntimeException {
    private static final long serialVersionUID = 5445442055796600764L;

    protected final Code code;

    protected final Object[] args;

    public ErrorCodeException(Code code, Object... args) {
        this(code, null, args);
    }

    public ErrorCodeException(Code code, Throwable cause, Object... args) {
        super(String.valueOf(code.code()), cause);
        this.code = code;
        this.args = args;
    }

    public Code getCode() {
        return code;
    }

    public Object[] getArgs() {
        return args;
    }

    @Override
    public String getMessage() {
        return "[" + code.code() + "]" + code.msg(args);
    }

}
